const { watch } = require('fs');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin'); // 引入copy-webpack-plugin插件

module.exports = {
  entry: {
    core: './src/core.ts', // 入口文件路径
    login: './src/login.ts' // 新增入口
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  }, 
  resolve: {
    extensions: ['.ts', '.tsmap', '.js'], // 添加.tsmap支持
  },
  output: {
    filename: '[name].js', // 支持多个入口
    path: path.resolve(__dirname, 'dist'),
    library: 'ispace', // 导出为库
    libraryTarget: 'umd', // 通用模块定义
    globalObject: 'this',
  },
  mode: 'production', // 或 'development' 根据需要
  watch: false,
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: 'public', to: '.' }, // 将public目录中的文件拷贝到dist目录中
        { from: 'src/login.html', to: '.' },
          {
            from: path.resolve(__dirname, 'node_modules/ispace_rscm/dist/index.js'),
            to: path.resolve(__dirname, 'dist/ispace_rscm/index.js'), // 输出到 dist/assets/
          },
      ],
    }),
  ],
};



